package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC722 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public List<String> removeComments(String[] source) {
            boolean inBlock = false;
            StringBuilder newline = new StringBuilder();
            List<String> ans = new ArrayList();
            for (String line : source) {
                int i = 0;
                char[] chars = line.toCharArray();
                if (!inBlock) newline = new StringBuilder();
                while (i < line.length()) {
                    if (!inBlock && i + 1 < line.length() && chars[i] == '/' && chars[i + 1] == '*') {
                        inBlock = true;
                        i++;
                    } else if (inBlock && i + 1 < line.length() && chars[i] == '*' && chars[i + 1] == '/') {
                        inBlock = false;
                        i++;
                    } else if (!inBlock && i + 1 < line.length() && chars[i] == '/' && chars[i + 1] == '/') {
                        break;
                    } else if (!inBlock) {
                        newline.append(chars[i]);
                    }
                    i++;
                }
                if (!inBlock && newline.length() > 0) {
                    ans.add(new String(newline));
                }
            }
            return ans;
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC722 an = new LC722();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
